﻿@page "/setting"
@namespace SwashbucklerDiary.Pages
@inherits PageComponentBase
@using SwashbucklerDiary.Models

<MyAppBar Title="@(I18n.T("Mine.Settings"))"
          OnClick="NavigateToBack">
</MyAppBar>

<ScrollContainer>
    <div class="text-h6 setting-title">
        @(I18n.T("Setting.General.Name"))
    </div>

    <MCard Class="setting-card"
           Elevation="0"
           Rounded="@("lg")">
        <MList>
            <MListItem OnClick="@(()=>To("permission"))">
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-account-cog-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.General.Permission.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MIcon>mdi-chevron-right</MIcon>
                </MListItemAction>
            </MListItem>

            <MDivider Class="mx-3"></MDivider>

            <MListItem OnClick="@(()=>ShowClearCache=true)">
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-trash-can-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.General.Storage.Name"))
                </MListItemContent>
                <MListItemContent Class="setting-state">
                    <MListItemSubtitle>
                        @CacheSize
                    </MListItemSubtitle>
                </MListItemContent>
                <MListItemAction>
                    <MIcon>mdi-chevron-right</MIcon>
                </MListItemAction>
            </MListItem>
        </MList>
    </MCard>

    <div class="text-h6 setting-title">
        @(I18n.T("Setting.Diary.Name"))
    </div>

    <MCard Class="setting-card"
           Elevation="0"
           Rounded="@("lg")">
        <MList>
            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-format-title
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Diary.Title.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="Title"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.Title)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(Title)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>

            <MDivider Class="mx-3"></MDivider>

            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-language-markdown-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Diary.Markdown.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="Markdown"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.Markdown)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(Markdown)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>

            <MDivider Class="mx-3"></MDivider>

            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-calendar-edit-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Diary.EditCreateTime.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="EditCreateTime"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.EditCreateTime)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(EditCreateTime)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>

            <MDivider Class="mx-3"></MDivider>

            <MListItem OnClick="@(()=>To("location"))">
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-map-marker-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Diary.Location.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MIcon>mdi-chevron-right</MIcon>
                </MListItemAction>
            </MListItem>
        </MList>
    </MCard>

    <div class="text-h6 setting-title">
        @(I18n.T("Setting.Safe.Name"))
    </div>

    <MCard Class="setting-card"
           Elevation="0"
           Rounded="@("lg")">
        <MList>
            @if (Privacy)
            {
                <MListItem OnClick="@(()=>To("privacyLibrary"))">
                    <MListItemIcon>
                        <MIcon Class="list-item-icon">
                            mdi-safe
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        @(I18n.T("Setting.Safe.PrivacyLibrary.Name"))
                    </MListItemContent>
                    <MListItemAction>
                        <MIcon>mdi-chevron-right</MIcon>
                    </MListItemAction>
                </MListItem>

                <MDivider Class="mx-3"></MDivider>
            }

            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        @(Privacy ? "mdi-lock-outline" : "mdi-database-remove-outline")
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(GetDisplayPrivacy())
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="Privacy"
                             TValue="bool"
                             Readonly="true"
                             OnClick="PrivacyClick"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(Privacy)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>

            @if (Privacy)
            {
                <MDivider Class="mx-3"></MDivider>

                <MListItem OnClick="()=>ShowPPSet = true">
                    <MListItemIcon>
                        <MIcon Class="list-item-icon">
                            mdi-key-outline
                        </MIcon>
                    </MListItemIcon>
                    <MListItemContent>
                        @(I18n.T("Setting.Safe.PrivacyPassword.Name"))
                    </MListItemContent>
                    <MListItemContent Class="setting-state">
                        <MListItemSubtitle>
                            @GetPrivatePasswordSetState()
                        </MListItemSubtitle>
                    </MListItemContent>
                    <MListItemAction>
                        <MIcon>mdi-chevron-right</MIcon>
                    </MListItemAction>
                </MListItem>
            }
        </MList>
    </MCard>
    <div class="text-h6 setting-title">
        @(I18n.T("Setting.Display.Name"))
    </div>

    <MCard Class="setting-card"
           Elevation="0"
           Rounded="@("lg")">
        <MList>
            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-calendar-range-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Display.Date.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="Date"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.Date)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(Date)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>
            <MDivider Class="mx-3"></MDivider>
            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-hand-wave-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Display.WelcomeText.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="WelcomText"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.WelcomeText)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(WelcomText)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>
            <MDivider Class="mx-3"></MDivider>
            <MListItem>
                <MListItemIcon>
                    <MIcon Class="list-item-icon">
                        mdi-emoticon-happy-outline
                    </MIcon>
                </MListItemIcon>
                <MListItemContent>
                    @(I18n.T("Setting.Display.DiaryCardIcon.Name"))
                </MListItemContent>
                <MListItemAction>
                    <MSwitch @bind-Value="DiaryCardIcon"
                             TValue="bool"
                             OnChange="SettingChange(SettingType.DiaryCardIcon)"
                             Dense="true"
                             Inset="true"
                             Color="white"
                             TrackColor="@MSwitchTrackColor(DiaryCardIcon)">
                    </MSwitch>
                </MListItemAction>
            </MListItem>
        </MList>
    </MCard>
</ScrollContainer>

<PasswordDialog @bind-Value="ShowPPSet"
                Title="@(I18n.T("Setting.Safe.SetPassword"))"
                MaxLength="20"
                OnOK="SetPassword">
</PasswordDialog>

<InputDialog @bind-Value="ShowPPInput"
             Title="@(I18n.T("Setting.Safe.ValidatePassword"))"
             Placeholder="@(I18n.T("Please input a password"))"
             MaxLength="20"
             Password="true"
             OnOK="InputPassword"
             OKText="@(I18n.T("Share.OK"))">
</InputDialog>

<MMDialog @bind-MyValue="ShowClearCache"
          MaxWidth="420">
    <MCard Rounded="@("lg")">
        <MCardTitle Class="font-weight-bold">
            @(I18n.T("Setting.General.Storage.Name"))
        </MCardTitle>
        <MCardText Class="pb-0">
            @(I18n.T("Storage.Content"))
        </MCardText>
        <MCardActions>
            <MSpacer></MSpacer>
            <MButton Text="true"
                     OnClick="()=>ShowClearCache=false">
                @(I18n.T("Share.Cancel"))
            </MButton>
            <MButton Text="true"
                     Color="red"
                     OnClick="ClearCache">
                @(I18n.T("Share.OK"))
            </MButton>
        </MCardActions>
    </MCard>
</MMDialog>